Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: compiler syntax Parser
Hi Smile | :)
 
I'm doing some research on compiler development, and am wanting to understand more about how the system works parsing using DFA tables. I see the theory of the operation of DFA table with parsers LALR, LL, LR, but I just can not understand.
As I am studying, I do not want to use a compiler compiler, such as ANTLR ... I want to understand how can I mount a tebela, make analyze syntactically with it, and make the parser and code gen...
 
So, with much searching, I found some code on the internet...
 
#define TAM_SIGMA 45
...
...
int edges[][TAM_SIGMA] = { {8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,0,0,0,0,5,4,2,3,9},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
        };
...
...
 

for example, if I have a very simple language:
 
function teste
    print("c")
return nil
 
function main
    var b = 10;
    print("a")
    teste()
return nil
 
How do I make a syntactic and semantic analysis on it, using a table DFA, I just can not understand this, as each state to define this matrix, as each letter, number, or symbol, represents something in the code.
 
I just can not understand how the machine works using an array as a basis, and that's what I want to know, how to build a simple parser using a DFA table, and how the parser will work in conjunction with it all, if you can post a sample code, I appreciate it.
Posted 13-Apr-13 18:22pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 13 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100