A question about Cobol-like language

Coordinator
Jun 17, 2008 at 5:20 PM
Edited Jun 17, 2008 at 9:24 PM
(this is a question from discussion post in "Create your first DSL" article, question posted by RugbyLeague)
You might be able to point me in the right direction. My language is a bit COBOLy in that you declare files etc outside the main body of the processing code - can Irony copy with such things? I have included a small test program written in my language to show how files etc are declared.


declare
i_urn: Int32
i_title: string
i_forename: string
i_surname: string
end
DelimitedTextReader
name = iDelim
pathname = "c:\demextract.txt"
has header record = yes
begin
i_urn
i_title
i_forename
i_surname
end
end
DelimitedTextWriter
name = oDelim
pathname = "c:\deleteme.csv"
has header record = true
force text qualifier = yes
delimiter = "|"
begin
i_urn
i_title
i_forename
i_surname
end
end
process
open iDelim
open oDelim
loop
read iDelim
until eof
^display i_urn, " - ", i_title, " ", i_forename, " ", i_surname
write oDelim
^
switch
case i_title = "Mrs"
display "MRS: ", i_title
case i_title = "Mr"
display "MR: ", i_title
case i_title = "Ms"
display "MS: ", i_title
case i_title = "Miss"
display "MISS: ", i_title
case i_title = "Dr"
display "DR: ", i_title
default
display "DEFAULT: ", i_title
endswitch
^display "hello"
^
#skip
i_forename = "1000"
if cancast i_forename to i_urn
cast i_forename to i_urn
^display i_urn
i_urn = -198
if cancast i_urn to i_forename
cast i_urn to i_forename
^display i_forename
endif
else
^display "Can't cast"
endif
#endskip
^
endloop
close oDelim
close iDelim
end
Coordinator
Jun 17, 2008 at 5:47 PM
Edited Jun 17, 2008 at 6:01 PM

Questions to Rugby (original poster):

I guess newlines and indentation are important. Is it so?

If yes, you need to start with adding CodeOutlineFilter that will recreate indentation and newLine symbols in the input stream (the scanner completely ignores the whitespace). Just write down the grammar using the Grammar.Indent, Grammar.NewLine, Grammar.Dedent terminals in BNF expressions. Then in your Grammar's constructor add the following statement: 

TokenFilters.Add(
new CodeOutlineFilter(true));

Let me know how it goes, and we'll proceed from there
thanks
Roman

 

 

Jun 19, 2008 at 10:47 AM

Hi Roman,

(I am RugbyLeague on CP)

Thanks for the reply.

Newlines are important but indentation isn't (except for readability)

I am currently reworking the language grammar. The language grew over time as I added new functionality in a rather haphazard way so it borrows a lot from other languages without ever having a clear grammar of its own (an advantage and a disadvantage of hand rolling the parser etc)

I need to get the language parser/compiler/runtime translated from C++ to C# in the next couple of weeks - I love realistic deadlines :( - so  I am planning to carry on as I am and then start to look at rewiring everything, hopefully with Irony which looks very promising.

Thanks

Jonathan.

 

Coordinator
Jun 25, 2008 at 4:22 PM

Hi

good luck, and let me know if you have any questions

Roman