1

I'm developing my own scripting language to solve some unique challenges for a project.

The language takes source code and converts the contents into tokens, and then a command factory is used to convert those tokens into something that can be executed.

An example of a script might look like this.

accept: always;
reject: title has "something" or body has "something else";
reject: title length < 10;

Each line in the script ends with a ; terminator, and each line starts with a named rule that ends with :. Each rule uses a command followed by arguments. The commands can be joined together using logical operators. The number of arguments a command can have is fixed. So when I find a command I can expect X number of additional tokens for the syntax to be correct. The goal is human readable code because non-programmers will be using it.

An alternative way of writing the same above code using a C style structure would be.

accept(true);
reject(has(title,"something") || has(body,"something else"));
reject(length(title) < 10);

What is the term used for a parser that handles a language where () for structuring arguments is omitted, and there are no clear boundaries defined for arguments.

I would like to read up on how these kinds of parsers are implemented. To ensure I'm not overly reinventing the wheel or running into common problems.

7
  • 3
    You ask the wrong question - you don't want to know what your parser is called (which depends on how you implement it), but if there is a name for that category of languages. I suggest you edit your question title.
    – Doc Brown
    Aug 16, 2013 at 10:52
  • @DocBrown very true, how's that new title?
    – Reactgular
    Aug 16, 2013 at 11:08
  • 1
    What is the command(s) in title length < 10? Also, you may need parentheses after all for grouping conditions. When you've sorted that out, a standard LR parser should to the job.
    – chirlu
    Aug 16, 2013 at 11:14
  • You missed my point - parsers are categorized into something like "bottom up", "top down", "recursive descent" (which may all be possible for your language). Replace "parser" by "language" and I think you will be fine.
    – Doc Brown
    Aug 16, 2013 at 11:14
  • @chirlu title length < 10 is the same as strlen(title) < 10 in most languages where title is a string variable.
    – Reactgular
    Aug 16, 2013 at 13:15

2 Answers 2

1

Obligatory LISP:

(accept t)
(reject-if (or (has title "something) (has body "something else")))
(reject-if (< (length title) 10)

Obligatory FORTH:

1 accept
"something" title has "something else" body has or reject-if
title length 10 < reject-if

The key is that you don't have to write and debug a custom parser for either of these approaches.

0

See off-side rule.

Generally, tokens are tokens though, and parentheses are tokens (operators really) just like keywords. Not having parentheses means that you are trying to stay away from the function call paradigm, but the semantics are still there in your examples far as I can tell. So I am not sure if you should be looking for differentiation at the parser rather than at the scanner level.

Another avenue to explore is the implementation of declarative/non-procedural languages like SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.