Tuesday, April 12, 2011

OMCC with error handling

I have been working on the thesis very hard lately, so far I have
accomplished this:

* Lexer and Parser
* Lexer and Parser Generator
* Error Handling

The last part is now working like this:

It uses error recovery to detect more errors, but it always fails at the end. Right now it only recovers from the action ERASE token, however if there are tokens with errors nearby it will stop parsing.

From the papers I read, I have this primary error handling techniques (single correction) which could be insert, replace or erase. So far I have not implemented MERGE because my parser only understand tokens and has no idea about the semantic value of the tokens. I need to implement a table to look for the semantic value, also important for displaying the errors with the right String not with the Token NAME as now.

***ERRORS WERE FOUND AND COULD NOT RECOVER ***

Syntax Error near [TOKEN:T_DO 'do' from (line:3 col:18) until (line:3
col:20)], ERASE token
Syntax Error near [TOKEN:T_ADD '+' from (line:4 col:13) until (line:4
col:14)], INSERT token {T_INTCONST or T_IDENT}
Syntax Error near [TOKEN:T_ADD '+' from (line:4 col:13) until (line:4
col:14)], REPLACE token with {T_LPAREN}
Syntax Error near [TOKEN:T_ADD '+' from (line:4 col:13) until (line:4
col:14)], ERASE token
Syntax Error near [TOKEN:T_IDENT 'y' from (line:8 col:5) until (line:8
col:6)], INSERT token {T_THEN}

program file:

1/* this is while test of comment */
2read x y z w;
3while x <> 99 do do
4 ans := (x++1) - (y/3);
5 write ans;
6 read x, y;
7 if x = 10
8 y := 234;
9 endif
10end


My thesis is getting close to the end, I hope it can be completed by the end of this month.

Wednesday, April 6, 2011

OMCC - (OpenModelica Compiler-Compiler)

Compiler-Compiler is a term that refers to a program that can generate a parser for compiler, so the new name after a deliberation with my Examiner is OMCC, having in mind that OMC is the command line instruction for the current compiler, I think that OMCC will be easily remembered for the new developers that start to work in this compiler and base their work on my thesis.

$omcc MetaModelica
..... Generating files
DONE!

Saturday, April 2, 2011

OMC-LPG OpenModelica Compiler - Lexer and Parser Generator

OMC-LPG (OpenModelica Compiler - Lexer and Parser Generator) is the name I came up to call my thesis. I realize when I was writing my report that it is difficult to write all the time the long name, so I needed a short, easy to remember and off course unique to name my project. This is how OMC-LPG was born.

The focus of my work during this week is been mainly on the report, after setting up the SVN environment and fixed some bugs with my supervisor on the OMC. It is time to rush with the report.

So far I have been writing about 3.600 words for the report in the last month, and well I don't count pages because it is pretty bulky but including the source code (which will change later) I got around 111 pages. By the way this is a pretty easy way to count words in a pdf under linux:

/thesis$ pdftotext MasterReport.pdf MasterReport.txt
/thesis$ wc -w MasterReport.txt
3591 MasterReport.txt

/thesis/code$ wc -w *.*
171 lexer10.l
934 Lexer10.mo
595 LexerCode10.mo
152 LexerCode.tmo
992 LexerGenerator.mo
930 Lexer.mo
848 LexTable10.mo
499 Main.mo
1294 ParseCode10.mo
137 ParseCode.tmo
626 parser10.y
2272 ParserGenerator.mo
1151 Parser.mo
1157 ParseTable10.mo
40 SCRIPT.mos
138 Token10.mo
11936 total



LaTeX is a formidable tool for professional text writers, I am glad I started earlier with this report because I got the opportunity to play around a bit with it without the pressure of time.

I have set as a deadline to finish both, project and report the last day of April. Let's see how this plan goes.

Friday, March 25, 2011

New omc-parser code project

I recently opened a google code project to handle all the source files of this master's thesis.

The link is here:

http://code.google.com/p/omc-parser/

Command-line access:

Use this command to anonymously check out the latest project source code:
# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://omc-parser.googlecode.com/svn/trunk/ omc-parser-read-only


It is a good place to keep my code safe and also to report all the issues that I get during the development.

I have just setup a development environment in Linux and I want to be able to switch and keep updated all my source code between both operative systems.

Soon I will write an article about software configuration management for students that are developing a thesis, and my experience with this website will definitely help.

Wednesday, March 23, 2011

Tables generator ready

Now my work consist on build part of the code automatically from the Flex and Bison code generated in C.

In order to build this it is necessary to read the lexer.c and parser.c file and generate the LexTable.mo ParseTable.mo that contains the arrays used for the automata machine, and the LexCode.mo and ParseCode.mo used for the actions after a token is found for lexer and a shift reduce rule to build the AST for the parser. The files Token.mo needs to be rebuild also from the parser.c code.

For making this machine customized for any language, it is necessary to link the generated files together with the main files Lexer.mo and Parser.mo, so those files will be generated also with a sufix which will identify the machine.

For my thesis, the exercise 10 and exercise 4 are the examples I am using for testing the machine, so the machines will contain all these files with the sufix 10 and 4 respectively.

Some code cleaning is still necessary to do, but this does not affect the current work, it will be complemented later after the Error Handled is improved in the parser.

Friday, March 11, 2011

Parser Prototype done

This week is been very productive, after a good explanation of how to build the AST, I manage to build the typed AST for MetaModelica, it means that the goals for the prototype are reached and now I can move to the next phase which is to build the Lexer Generator.




There are still things to do, like cleaning the code from unused variables and better performance of the loops, besides the error handling which is another major milestone in this project.

Thursday, March 10, 2011

The Parser is now Parsing

After dealing with the C code generated by BISON, with more than 15 arrays and crazy GOTO statements, I have managed to create the first parser in MetaModelica that parses the exercise 10 of the MetaModelica examples (for those who have read the MetaModelica Document).

For the rest of the mortals, what I have achieve is to make the code of a program to be recognized by another program (Compiler Parser). However there are more stuff to do before this task is complete, including the generation of the AST, error handling and cleaning of the code.

It is now week 10 and hopefully 10 weeks more to go and finish this project. Next activities will be to focus on the MetaModelica code generation based on the Flex and Bison files.