Welcome Guest ( Log In | Register )

Bump Topic Topic Closed RSS Feed

Outline · [ Standard ] · Linear+

> Writing a parser

views
     
TSFlierMate
post Mar 31 2021, 08:46 PM, updated 2w ago

Getting Started
**
Junior Member
155 posts

Joined: Nov 2020


I try to keep my posts as low as possible, but I might post more in coming weeks or months as I get excited with my own set of programming language (with its back-end compiler!). Please support my Sambal compiler.... Now here goes:

I plan to introduce variables , iteration construct, and conditional statement in my own Sambal programming language.

Your inputs are welcomed.

Variables:

Which is the best for easy and quick Sambal language?

CODE

LET a = 0

VAR a = 0

SET a = 1

a = 95

DIM a as integer


Iteration construct:

Which is the best for easy and quick Sambal language?

CODE

REPEAT.....UNTIL a = 2

DO .....LOOP UNTIL a =3

WHILE a < 3.....WEND




Conditional statements:

Which is the best for easy and quick Sambal language?
But I think it is rather straight forward.

CODE

IF a = 3 THEN.....

IF a <2 THEN BEGIN.....END




And finally, do you agree I design it in this way:
CODE

INC a
DEC a
a = a + 2
a = a - c


No complex mathematic calculation will be supported. Only one subtraction or one addition of variable.

Do you recommend to use line delimiter such as semicolon? My own vision is that to make the Sambal language code as simple as possible to type and to memorize.

Currently only 4 commands are supported: MSGBOX, WMSGBOX, EMSGBOX, QMSGBOX.
But I plan to add the above to Sambal compiler.

This post has been edited by FlierMate: Apr 10 2021, 08:54 PM
Lord Tiki Mick
post Apr 1 2021, 01:08 AM

Enthusiast
*****
Senior Member
993 posts

Joined: Jul 2012
What would the typing system be? Dynamic?
TSFlierMate
post Apr 1 2021, 01:32 AM

Getting Started
**
Junior Member
155 posts

Joined: Nov 2020


QUOTE(Lord Tiki Mick @ Apr 1 2021, 01:08 AM)
What would the typing system be? Dynamic?
*
Do you mean data types of variables? I think I will implement "string" and "integer"(16-bit or 32-bit) only.

I forgot or have never really grasped the meaning of dynamic typing system.

My compiler will look for the first assigned value of a variable, if in the beginning, "string" is assigned, the compiler would remember it is "string" data type till the end. It is not interchangeable with "integer" during compile-time. So it is more like PHP?

Now I have issue such as range checking, to generate error message if integer is overflow, etc. But it would be fun creating this parser and compiler.

Lord Tiki Mick, I might need more ideas from you in the progress.

Lord Tiki Mick
post Apr 1 2021, 02:17 AM

Enthusiast
*****
Senior Member
993 posts

Joined: Jul 2012
QUOTE(FlierMate @ Apr 1 2021, 01:32 AM)
Do you mean data types of variables? I think I will implement "string" and "integer"(16-bit or 32-bit) only.

I forgot or have never really grasped the meaning of dynamic typing system.

My compiler will look for the first assigned value of a variable, if in the beginning, "string" is assigned, the compiler would remember it is "string" data type till the end. It is not interchangeable with "integer" during compile-time. So it is more like PHP?

Now I have issue such as range checking, to generate error message if integer is overflow, etc. But it would be fun creating this parser and compiler.

Lord Tiki Mick, I might need more ideas from you in the progress.
*
It's possibly a strongly typed system and the type is inferred.

Dynamically typed means type checking happens at runtime and variable doesn't hold the type.

There's also a concept of mutability. Is your language mutable by default or immutable by default? If you use the VAR approach, you can have another keyword VAL, so VAR means it's mutable, while VAL is immutable. smile.gif

BTW, your language looks too similar to visual basic. sweat.gif
TSFlierMate
post Apr 1 2021, 02:42 PM

Getting Started
**
Junior Member
155 posts

Joined: Nov 2020


QUOTE(Lord Tiki Mick @ Apr 1 2021, 02:17 AM)
It's possibly a strongly typed system and the type is inferred.

Dynamically typed means type checking happens at runtime and variable doesn't hold the type.

There's also a concept of mutability. Is your language mutable by default or immutable by default? If you use the VAR approach, you can have another keyword VAL, so VAR means it's mutable, while VAL is immutable. smile.gif

BTW, your language looks too similar to visual basic.  sweat.gif
*
I don't think I want to introduce constant in the language set, if it is what I understand of mutability. But I learn new terminology from you.

I had been influenced by VB a lot, that's why almost all the syntax and identifier look similar to Visual Basic. :-D
TSFlierMate
post Apr 5 2021, 02:49 PM

Getting Started
**
Junior Member
155 posts

Joined: Nov 2020


Now that I have implement integer variable and simple arithmetic, I am having a quite big issue to implement conditional statements in my language. The problem is what if coders write deeply nested IF....THEN...ELSE..? I would having a hard time to write the parser and generate the Assembly code with multiple jumps.

Maybe someone can just give some hints on solution on how to parse the code with nested IF...THEN....ELSE?

Use binary tree? shakehead.gif

This post has been edited by FlierMate: Apr 5 2021, 03:33 PM
chibiheroes
post Apr 7 2021, 04:55 PM

Getting Started
**
Junior Member
61 posts

Joined: Nov 2009


No mate, you don't use binary tree, you use lexer. This lexer basically parses your source code into a list of tokens, which is fed into a parser that turns that list into a tree of nodes, aka Abstract Syntax Tree. First and foremost though, you need to KNOW why you making a new language, so you ask questions like:

1 .What execution paradigm do we want to use? Will it be imperative or functional? Or maybe based on state machines or business rules? C vs Lisp
2. Do we want static typing or dynamic typing? Java vs Python
3. What sort of programs this language will be best at? Will it be used for small scripts or large systems? Haskell vs C++
4. What matters most to us: performance? Readability? C vs Python
5. Do we want it to be similar to an existing programming language? Will it be aimed at C developers or easy to learn for who is coming from Python?
6. Do we want it to work on a specific platform (JVM, CLR)?
7. What sort of metaprogramming capabilities do we want to support, if any? Macros? Templates? Reflection?

I'm too lazy to type so just google and check it out tongue.gif tongue.gif tongue.gif
malleus
post Apr 8 2021, 07:42 AM

Regular
******
Senior Member
1,663 posts

Joined: Dec 2011
QUOTE(FlierMate @ Apr 5 2021, 02:49 PM)
Now that I have implement integer variable and simple arithmetic, I  am having a quite big issue to implement conditional statements in my language. The problem is what if coders write deeply nested IF....THEN...ELSE..? I would having a hard time to write the parser and generate the Assembly code with multiple jumps.

Maybe someone can just give some hints on solution on how to parse the code with nested IF...THEN....ELSE?

Use binary tree?  shakehead.gif
*
remember doing this during undergrad. given a fictional language, we write a compiler for it.

vaguely remember it consists of 2 steps: parsing followed by lexical analysis

check out Bison and Flex for this
chibiheroes
post Apr 8 2021, 11:35 AM

Getting Started
**
Junior Member
61 posts

Joined: Nov 2009


My memory is hazy since I haven't done compiler programming since 1999 but I think there are better parser generator than Bison/Flex like ANTLR, just do a google for compiler-compiler.
TSFlierMate
post Apr 8 2021, 06:23 PM

Getting Started
**
Junior Member
155 posts

Joined: Nov 2020


QUOTE(malleus @ Apr 8 2021, 07:42 AM)
remember doing this during undergrad. given a fictional language, we write a compiler for it.

vaguely remember it consists of 2 steps: parsing followed by lexical analysis

check out Bison and Flex for this
*
QUOTE(chibiheroes @ Apr 8 2021, 11:35 AM)
My memory is hazy since I haven't done compiler programming since 1999 but I think there are better parser generator than Bison/Flex like ANTLR, just do a google for compiler-compiler.
*
At least now I know the keyword to search for is lexer and its lexical analysis. Thanks to both of you!

Topic ClosedOptions
 

Change to:
| Lo-Fi Version
0.0222sec    0.68    5 queries    GZIP Disabled
Time is now: 19th April 2021 - 08:55 AM